www.gusucode.com > XerCMS 携云PHP企业建站程序 v2015PHP源码程序 > XerCMS 携云PHP企业建站程序 v2015/XerCMS_v20150724/XerCMS_v20150724/XerCMS/Library/XerCMS_data.php

    <?php
/**
 * @name     XERCMS
 * @author   Arno <XerCMS@163.com> [QQ:1328013]
 * @version  1.0.0
 * @link     http://www.XerCMS.com 
 */

!defined('XERCMS') && exit('Access Denied');

class Data
{
     var $var = array();
     
     function Data($file = null) {
          if(!empty($file)) {
               $this->file($file);
          }
     }
     
     public function file($name) {
          if(!isset($this->$var[$name])) {
               $this->$var[$name] = strpos($name,'#') === 0 ? include(INC.'Data/'.$name.'.php') : include(INC.'Data/'.$name.'.php');
          }
     }

     static public function del($file) {
          return @unlink(INC.'Data/'.$file);
     }
     
     static public function edit($file,$data) {
          
     }
     
     static public function write($file,$data) {
          $file = INC.'Data/'.$file;
          $handle = fopen($file,'w+');
          while(true) {
               if(flock($handle,LOCK_EX)) {
                    fwrite($handle,$data);
                    flock($handle,LOCK_UN);
                    break;
               } else sleep(1); 
          }
          return;         
     }
     
     static public function build($file,$data) {
          $file = explode('#',$file);
          if(count($file) == 2) {
               $file = DIR.'Data/'.$file[1].'.php';
          } else {
               $file = INC.'Data/'.$file[0].'.php';
          }
          $handle = fopen($file,'w+');
          while(true) {
               if(flock($handle,LOCK_EX)) {
                    fwrite($handle,'<?php !defined(\'XERCMS\') && exit(\'Access Denied\'); return '.AtoS($data,true).'; ?>');
                    flock($handle,LOCK_UN);
                    break;
               } else sleep(1); 
          }
          return;
     }
}
?>